package com.gimi.cloud.jimi.queue.revicer;

import java.io.IOException;
import java.util.Date;

import com.gimi.cloud.jimi.common.mq.enume.QueueConstant;
import com.gimi.cloud.jimi.dao.dao.sys.SysMqLogDao;
import com.gimi.cloud.jimi.dto.app.moreInfo.GongjijingDTO;
import com.gimi.cloud.jimi.entity.sys.SysMqLogEntity;
import com.gimi.cloud.jimi.queue.service.FengchaoGongjijingService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;


import com.rabbitmq.client.Channel;

/**
 * 蜂巢公积金队列
 * @author lilinfeng
 */
@Component
public class FengchaoGongjijingReceived {
	
	private static final Logger log = LoggerFactory.getLogger(FengchaoGongjijingReceived.class);
	
	@Autowired
	FengchaoGongjijingService fengchaoGongjijingService;
	@Autowired
	SysMqLogDao sysMqLogDao;

	/**
	 * 获取报告
	 * @throws IOException 
	 */
	@RabbitListener(queues = { QueueConstant.FGR_QUEUE_NAME })
	public void getReport(Message message, Channel channel, GongjijingDTO gongjijingDTO) throws IOException{
		SysMqLogEntity mqLog = new SysMqLogEntity();
		mqLog.setName("蜂巢公积金队列");
		mqLog.setStartTime(new Date());
		mqLog.setUserId(gongjijingDTO.getUserId());
		mqLog.setParam(gongjijingDTO.toString());
		try {
			fengchaoGongjijingService.getReport(gongjijingDTO);
		}catch(Exception e){
			log.info("获取报告失败，已自动取消!");
			e.printStackTrace();
        }finally {
            channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);
        }
		mqLog.setEndTime(new Date());
		sysMqLogDao.insertSelective(mqLog);
	}
}
